import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { defHttp } from '/@/utils/http/axios';

export const columns : BasicColumn[] = [
  {
    title: '产品名称',
    dataIndex: 'productName'
  },
  {
    title: '产品分类',
    dataIndex: 'categoryName'
  },
  {
    title: '接入方式',
    dataIndex: 'accessName'
  },
  {
    title: '产品描述',
    dataIndex: 'productRemark'
  },
  {
    title: '创建时间',
    dataIndex: 'createTime'
  },
];

export const searchFormSchema : FormSchema[] = [
  {
    label: '产品分类',
    field: 'categoryId',
    component: 'ApiTreeSelect',
    componentProps: {
      api: () => defHttp.get({ url: '/device/productCategory/list' }),
      showSearch: true,// 开启搜索
      placeholder: '请选择产品分类',
      treeNodeFilterProp: 'categoryName', // 这里要指定和label或者value字段同一个属性
      fieldNames: {
        label: "categoryName",
        key: "categoryId",
        value: "categoryId",
      },
      getPopupContainer: () => document.body,
    }

  },
  {
    label: '产品名称',
    field: 'productName',
    component: 'Input'
  },
];

export const formSchema : FormSchema[] = [
  // TODO 主键隐藏字段，目前写死为ID
  { label: '', field: 'productId', component: 'InputNumber', show: false },
  { label: '', field: 'isEdit', component: 'InputNumber', show: false },
  {
    label: '产品名称',
    field: 'productName',
    component: 'Input',
    rules: [{ required: true, message: "请输入产品名称" }],
    dynamicDisabled: ({ values }) => {
      if (values.isEdit != undefined && values.isEdit == true) {
        return true
      } else {
        return false
      }
    },
  },
  {
    label: '产品分类',
    field: 'categoryId',
    component: 'ApiTreeSelect',
    componentProps: {
      api: () => defHttp.get({ url: '/device/productCategory/list' }),
      showSearch: true,// 开启搜索
      placeholder: '请选择产品分类',
      treeNodeFilterProp: 'categoryName', // 这里要指定和label或者value字段同一个属性
      fieldNames: {
        label: "categoryName",
        key: "categoryId",
        value: "categoryId",
      },
      getPopupContainer: () => document.body,
    },
    rules: [{ required: true, message: "请选择产品分类" }],
    dynamicDisabled: ({ values }) => {
      if (values.isEdit != undefined && values.isEdit == true) {
        return true
      } else {
        return false
      }
    },
  },
  {
    label: '接入方式',
    field: 'accessId',
    component: 'ApiSelect',
    componentProps: {
      api: () => defHttp.get({ url: '/dictCommon/getAccessList' }),
      //数值转成String
      numberToString: false,
      //标题字段
      labelField: 'accessName',
      //值字段
      valueField: 'accessId',
      //请求参数
      params: {},
      //返回结果字段
      resultField: 'records',
    },
    rules: [{ required: true, message: "请选择接入方式" }],
    dynamicDisabled: ({ values }) => {
      if (values.isEdit != undefined && values.isEdit == true) {
        return true
      } else {
        return false
      }
    },
  },
  {
    label: '产品描述',
    field: 'productRemark',
    component: 'Input',
    dynamicDisabled: ({ values }) => {
      if (values.isEdit != undefined && values.isEdit == true) {
        return true
      } else {
        return false
      }
    },
  }
];
